package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.mysql.MysqlLink;
import com.ruoyi.system.domain.DatabaseDetails;
import org.springframework.stereotype.Controller;

import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 数据库Controller
 *
 * @author jw
 * @date 2022-06-13
 */
@Controller
@RequestMapping("/system/details")
public class DatabaseDetailsController extends BaseController
{
    private String prefix = "system/database";



    @GetMapping()
    public String details()
    {
        return prefix + "/details";
    }

    /**
     * 查询数据库列表
     */
    @PostMapping("/databaseList")
    @ResponseBody
    public AjaxResult databaseList(DatabaseDetails databaseDetails, ModelMap mmap)
    {
        startPage();
//        List databaseList = MysqlLink.getAllDatabase(databaseDetails.getIp(),databaseDetails.getPort(),databaseDetails.getRoot(),databaseDetails.getPassword(),"1");
        List databaseList = MysqlLink.getAllDatabase("127.0.0.1","3306","root","123456","1");
        return AjaxResult.success(databaseList);
    }

    /**
     * 查询所选数据库的所有表
     */
    @PostMapping("/edit")
    @ResponseBody
    public String editSave(DatabaseDetails databaseDetails, ModelMap mmap)
    {
        List databaseList = MysqlLink.getAllDatabase("127.0.0.1","3306","root","123456","jw");
        mmap.put("tables", databaseList);
        return  "system/details/tables";
    }


}
